<!DOCTYPE html>
<html >
	<head>
		<meta charset="utf-8" />
		<script type="text/javascript" src="../js/angular.js" ></script>
		<title></title>
	</head>

	<body ng-app="app" >
		<div ng-controller="ctrl" >
			<table border="1" width="600" >
				<tr>
					<td ng-click="orderby('id')" >id</td>
					<td ng-click="orderby('name')">名称</td>
					<td ng-click="orderby('url')">url</td>
				</tr>
				<tr ng-repeat="v in data" >
					<td>{{v.id}}</td>
					<td>{{v.name}}</td>
					<td>{{v.url}}</td>
				</tr>
			</table>
		</div>
		<script>
			var app=angular.module("app",[]);
			app.controller("ctrl",["$scope","$filter",function($scope,$filter){
                $scope.data=[
                    {id:1,name:"张三",url:"http://baidu.com"},
					{id:2,name:"李四",url:"http://163.com"},
					{id:3,name:"王五",url:"http://163.com"},
					{id:4,name:"周六",url:"http://163.com"}
					];
//                var filtd={};
//				$scope.orderby=function (filter) {
//				    if(filtd[filter]==undefined)
//					{
//                        filtd[filter]=true;
//					}else {
//                        filtd[filter]=!filtd[filter];
//					}
//					$scope.data=$filter('orderBy')($scope.data,filter,filtd[filter]);
//                }

                $scope.orderby=function (filter) {
                    if(arguments.callee[filter]==undefined){
                        arguments.callee[filter]=true;
					}else {
                        arguments.callee[filter]=!arguments.callee[filter];
					}
                    $scope.data=$filter('orderBy')($scope.data,filter,arguments.callee[filter]);
                }
			}]);
		</script>
	</body>
</html>
